package repository

import (
	"context"
	"github.com/aphasia51/website/internal/domain"
	"github.com/aphasia51/website/internal/repository/dao"
)

type SafetyEducationRepository struct {
	dao *dao.SafetyEducationDAO
}

func NewSafetyEducationRepository(dao *dao.SafetyEducationDAO) *SafetyEducationRepository {
	return &SafetyEducationRepository{
		dao: dao,
	}
}

func (r *SafetyEducationRepository) Query(ctx context.Context, a domain.SafetyEducation) ([]domain.SafetyEducation, error) {
	safetyEducation, err := r.dao.Query(ctx, dao.SafetyEducation{
		Category:   a.Category,
		ModuleName: a.ModuleName,
	})

	if err != nil {
		return []domain.SafetyEducation{}, err
	}

	safetyEducations := make([]domain.SafetyEducation, 0)
	for _, v := range safetyEducation {
		safetyEducations = append(safetyEducations, domain.SafetyEducation{
			Category:     v.Category,
			ModuleName:   v.ModuleName,
			ModuleNameEn: v.ModuleNameEn,
			Content:      v.Content,
			ContentEn:    v.ContentEn,
		})
	}

	return safetyEducations, nil
}
